package com.ynny.controller;

import com.ynny.entity.ResultData;
import com.ynny.entity.User;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

//@Controller
//@ResponseBody
@RestController
public class DataParamTest02Controller {


    // 测试数据绑定
    @PostMapping("/testPostMethod01")
    public String test01(User user) {
        System.out.println(user);
        return "test01PostMethod";
    }


    // 测试JSON数据绑定
    @PostMapping("/testPostMethod02")
    public String testPostJSON02(@RequestBody User user) {
        System.out.println(user);
        return "testPostJSONMethod02";
    }

    // 测试JSON数据绑定
    @PostMapping("/testPostMethod03")
    public List<Object> testPostJSON03(@RequestBody User user) {

        ArrayList<Object> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {

            list.add(user);

        }

        System.out.println(user);
        return list;
    }


    // 测试JSON数据绑定
    @PostMapping("/testPostMethod04")
    public ResultData testPostJSON04(@RequestBody User user) {

        ArrayList<Object> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {

            list.add(user);

        }

        ResultData rs = new ResultData();
        rs.setCode(200);
        rs.setMessage("成功");
        rs.setData(list);

        return rs;
    }
}
